package com.qiwenshare.file.config.checkuser;

import com.qiwenshare.file.config.security.filter.NoLoginExceptionFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

import java.util.Arrays;

@Configuration
public class CheckuserConfig {

    private String[] excludeUris = {"/user/register",
            "/user/login",
            "/user/checkuserlogininfo",
            "/filetransfer/downloadfile",
            "/filetransfer/batchDownloadFile",
            "/filetransfer/preview",
            "/share/sharefileList",
            "/share/sharetype",
            "/share/checkextractioncode",
            "/share/checkendtime",
            "/file/query",
            "/file/queryfilelist",
            "/sso/logonout",
            "/sso/",
            "/notice/list",
            "/notice/detail",
            "/param/grouplist",
            "/office/IndexServlet"
    };

    private String[] antPathUris = {"/*.html",
            "/**/*.html",
            "/**/*.css",
            "/**/*.js",
            "/swagger-ui/**",
            "/webSocket/**",
            "/error/**"};

    @Bean
    public FilterRegistrationBean exceptionFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        NoLoginExceptionFilter noLoginExceptionFilter = new NoLoginExceptionFilter();
        noLoginExceptionFilter.setExcludes(Arrays.asList(excludeUris));
        noLoginExceptionFilter.setAntPaths(Arrays.asList(antPathUris));
        registration.setFilter(noLoginExceptionFilter);
        registration.setName("noLoginExceptionFilter");
        registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return registration;
    }
}
